﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using GroupManager.Class;
namespace GroupManager
{
    public partial class ThemKhenThuong : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                int nam = DateTime.Now.Year;
                for (int i = nam - 1; i < nam + 2; i++)
                {
                    drlNam.Items.Add(i.ToString());
                }
                drlNam.SelectedIndex = 1;
            }
        }

        protected void btLuuNhap_Click(object sender, EventArgs e)
        {
            string tenKhenThuong = txtTenKhenThuong.Text.Trim();
            if (string.IsNullOrEmpty(tenKhenThuong))
            {
                ScriptManager.RegisterStartupScript(this, this.GetType(), "alert", "alert('Bạn phải nhập tên khen thưởng!');", true);
                return;
            }
            string donViCap = txtDonViCap.Text.Trim();
            string cap = txtCap.Text.Trim();
            int nam = int.Parse(drlNam.Text);
            string mdoinhom = Request.QueryString["doinhom"];
            int madoinhom = int.Parse(mdoinhom);
            LopKhenThuong.ThemKhenThuong(tenKhenThuong, donViCap, cap, nam, false, madoinhom, "");
            btHienThi.Enabled = false;
            btLuuNhap.Enabled = false;
        }

        protected void btHienThi_Click(object sender, EventArgs e)
        {
            string tenKhenThuong = txtTenKhenThuong.Text.Trim();
            if (string.IsNullOrEmpty(tenKhenThuong))
            {
                ScriptManager.RegisterStartupScript(this, this.GetType(), "alert", "alert('Bạn phải nhập tên khen thưởng!');", true);
                return;
            }
            string donViCap = txtDonViCap.Text.Trim();
            string cap = txtCap.Text.Trim();
            int nam = DateTime.Now.Year;
            string mdoinhom = Request.QueryString["doinhom"];
            int madoinhom = int.Parse(mdoinhom);
            LopKhenThuong.ThemKhenThuong(tenKhenThuong, donViCap, cap, nam, true, madoinhom, "");
            btHienThi.Enabled = false;
            btLuuNhap.Enabled = false;
        }
    }
}